package arrary;

import java.util.Random;

public class Arr8 {
    public static void main(String[] args) {
        //定义数组，打乱顺序1-5
        int [] arr ={1,2,3,4,5};
        Random r = new Random();
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            //生成随机索引
            int num = r.nextInt(arr.length);
            //随即索引的元素跟i指向的元素交换
            int temp = arr[i];
            arr[i] = arr[num];
            arr[num] = temp;
        }
        //循环结束后，数据中所有数组打乱
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
